#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Fragment
{
    int length;
    int offset;
};

vector<Fragment> fragmentPacket(int packetLength, const vector<int> &pathMTUs)
{
    vector<Fragment> fragments;
    if (pathMTUs.empty() || packetLength < 20)
        return fragments;

    const int headerSize = 20;
    int dataLength = packetLength - headerSize;
    int minMTU = *min_element(pathMTUs.begin(), pathMTUs.end());

    int maxDataPerFragment = (minMTU - headerSize) / 8 * 8;
    if (maxDataPerFragment <= 0)
        return fragments;

    int offset = 0;
    while (offset < dataLength)
    {
        int remaining = dataLength - offset;
        int currData = min(remaining, maxDataPerFragment);
        currData = currData / 8 * 8;

        if (currData == 0)
            break;
        fragments.push_back({currData + headerSize, offset});
        offset += currData;
    }

    return fragments;
}

// 测试用例
int main()
{
    auto case1 = fragmentPacket(500, {1500});
    cout << "Case1 - Single fragment:\n";
    for (auto &f : case1)
        cout << "Length:" << f.length << " Offset:" << f.offset << endl;

    auto case2 = fragmentPacket(1500, {500});
    cout << "\nCase2 - Multiple fragments:\n";
    for (auto &f : case2)
        cout << "Length:" << f.length << " Offset:" << f.offset << endl;

    auto case3 = fragmentPacket(1000, {600, 500, 450});
    cout << "\nCase3 - Path MTU changes:\n";
    for (auto &f : case3)
        cout << "Length:" << f.length << " Offset:" << f.offset << endl;

    return 0;
}